﻿using ConfigServices;
using LogServices;
using MailServices;
using Microsoft.Extensions.DependencyInjection;

namespace MailSenderConsoleApp
{
    internal class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello, World!");

            ServiceCollection services = new ServiceCollection();
            services.AddScoped<IConfigService, EnvVarConfigService>();
            //services.AddScoped<IConfigService, IniFileConfigService>(_ => new IniFileConfigService() { FilePath = "mail.ini" });
            services.AddIniFileConfigService("mail.ini");
            services.AddLayeredConfigReader();

            services.AddScoped<IMailService, MailService>();
            //services.AddScoped<ILogProvider, ConsoleLogProvider>();
            services.AddConsoleLog();

            using(var sp = services.BuildServiceProvider())
            {
                // 第一个根对象只能用ServiceLocator
                var mailService = sp.GetRequiredService<IMailService>();
                mailService.Send("Hello", "trump@usa.com", "懂王你好");
            }
        }
    }
}
